home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 11
/
CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso
/
cucd
/
programming
/
oberonv4
/
source
/
system
/
console.mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1996-08-11
|
4KB
|
122 lines
Syntax10.Scn.Fnt
Syntax10b.Scn.Fnt
ParcElems
Alloc
MODULE Console; (** cn, RD 1996-06-17 *)
(** Console writes to StdOut of the base OS. *)
(** Only use this for debugging and error messages from modules loaded before System.Log is available. *)
(** Note: this module does not convert chars from Oberon to the base OS char table. *)
(** See and update if necessary the history at the bottom of the file. *)
IMPORT SYSTEM, HostSYS, Reals;
(* Write CHAR to StdOut *)
PROCEDURE Ch*(ch:CHAR);
VAR str: ARRAY 2 OF CHAR;
BEGIN
str[0]:=ch;
HostSYS.StdOut(str, 1)
END Ch;
(* Write string to StdOut *)
PROCEDURE Str*(str: ARRAY OF CHAR);
VAR i:INTEGER;
BEGIN
i:=0; WHILE str[i]#0X DO INC(i) END;
HostSYS.StdOut(str, i)
END Str;
(* Write linefeed to StdOut *)
PROCEDURE Ln*; BEGIN Ch(HostSYS.toHost(00DX)) END Ln;
(* Write LONGINT to StdOut *)
PROCEDURE Int*(x:LONGINT);
i,n:INTEGER;
a:ARRAY 16 OF CHAR;
BEGIN
a[0]:=" ";
IF x=MIN(LONGINT) THEN
Str(" -2147483648")
ELSE
i:=1;
IF x<0 THEN
a[1]:="-";
i:=2;
x:=-x
END;
n:=15;
REPEAT
a[n]:=CHR(x MOD 10+ORD('0'));
x:=x DIV 10;
DEC(n)
UNTIL x=0;
REPEAT
INC(n);
a[i]:=a[n];
INC(i)
UNTIL n=15;
HostSYS.StdOut(a,i)
END Int;
(* RETURN hex char of INTEGER *)
PROCEDURE hexDigit(j:LONGINT):CHAR;
BEGIN
IF j<10 THEN RETURN CHR(j+ORD('0')) ELSE RETURN CHR(j+(ORD('A')-10)) END
END hexDigit;
(* Write LONGINT to StdOut in hex format *)
PROCEDURE Hex*(x:LONGINT); (* Texts.WriteHex *)
i: INTEGER;
a: ARRAY 10 OF CHAR;
BEGIN
i := 8; a[0]:=" ";
REPEAT
a[i]:=hexDigit(x MOD 10H);
x := x DIV 10H; DEC(i)
UNTIL i = 0;
HostSYS.StdOut(a,9)
END Hex;
(* Write anything in hex format to StdOut *)
PROCEDURE Dump*(VAR a: ARRAY OF SYSTEM.BYTE);
i: LONGINT;
d: INTEGER;
s: ARRAY 3 OF CHAR;
BEGIN
s[0]:=" ";
FOR i:=0 TO LEN(a)-1 DO
d:=ORD(SYSTEM.VAL(CHAR, a[i]));
s[1]:=hexDigit(d DIV 10H);
s[2]:=hexDigit(d MOD 10H);
HostSYS.StdOut(s,3)
END Dump;
(* Write BOOLEAN as TRUE or FALSE to StdOut *)
PROCEDURE Bool*(b: BOOLEAN);
BEGIN
IF b THEN Str(" TRUE") ELSE Str(" FALSE") END
END Bool;
(* Write LONGREAL to StdOut *)
PROCEDURE Real*(x: LONGREAL); (* Texts.WriteLongReal *)
e, n, i: INTEGER; x0: LONGREAL;
d, a: ARRAY 24 OF CHAR;
BEGIN
n:=8;
e := Reals.ExpoL(x);
IF e = 0 THEN
Str(" 0")
ELSIF e = 2047 THEN
Str(" NaN")
ELSE
a[0]:=" "; i:=1;
IF x < 0 THEN a[1]:="-"; i:=2 END;
e := SHORT(LONG(e - 1023) * 77 DIV 256);
IF e >= 0 THEN x := x / Reals.TenL(e) ELSE x := Reals.TenL(-e) * x END ;
IF x >= 10.0D0 THEN x := 0.1D0 * x; INC(e) END ;
x0 := Reals.TenL(n-1); x := x0*x + 0.5D0;
IF x >= 10.0D0*x0 THEN x := 0.1D0 * x; INC(e) END ;
Reals.ConvertL(x, n, d);
DEC(n); a[i]:=d[n]; INC(i); a[i]:="."; INC(i);
REPEAT DEC(n); a[i]:=d[n]; INC(i) UNTIL n = 0;
a[i]:="D"; INC(i);
IF e < 0 THEN a[i]:="-"; e := -e ELSE a[i]:="+" END; INC(i);
a[i]:=CHR(e DIV 100 + 30H); INC(i); e := e MOD 100;
a[i]:=CHR(e DIV 10 + 30H); INC(i);
a[i]:=CHR(e MOD 10 + 30H); INC(i);
HostSYS.StdOut(a, i)
END Real;
END Console.
Date Author Modification
1996-06-17 degner@pallas.amp.uni-hannover.de Created first unified version.